<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2020/3/9
 * Time: 17:53
 */
namespace app\franchisee\controller;
use think\Db;
//定时任务
class Timing extends Base {
    //询价单-定时任务
    public function Timing(){
        $time = date('Y-m-d H:i:s',strtotime("-2 hour"));
        $where['order_type'] = 1;
        $where['order_true'] =2;
        $where['order_status'] =4;
        $res = Db::table('up_order')->where($where)->select();
        foreach ($res as $key=>$vo){
            $list = Db::table('up_order')->where('order_id',$vo['order_id'])->find();
            if($time<$vo['send_date']){//大于当前时间2个小时
                $data['order_true'] =1;
                $data['order_status'] =5;
                Db::table('up_order')->where('order_id',$vo['order_id'])->update($data);
                $data2 = Db::table('up_u_user')->where('user_id',$list['order_dirver_user'])->find();
                $data1 = Db::table('up_u_user')->where('user_id',$list['order_jms_user'])->find();
                //插入消息表
                $dataList['n_title'] = '您的电子协议已被加盟商确认，请尽快赶往装货地点装货';
                $dataList['n_type'] =  2;
                $dataList['n_notice_type'] = 2;
                $dataList['n_user_id'] = ','.$list['order_dirver_user'].',';
                $dataList['n_read'] = ',0,';
                $dataList['n_delete'] = ',0,';
                $dataList['n_time'] = date('Y-m-d H:i:s');
                $dataList['n_status'] = 2;
                Db::table('up_notice')->insertGetId($dataList);
                YzxSms($data1['user_company_name']?$data1['user_company_name']:'平台', $data2['user_phone'], '',562125);//发送验证码
            }

        }
    }
}